/**
 * Created by mapbar_front on 2019/8/6.
 */
import React,{Component} from 'react';

const Ref1516 = (WrappedComponent)=> {
    console.log('WrappedComponent',WrappedComponent);
    class LogProps extends Component{
        //static displayName = `LogProps(${getDisplayName(WrappedComponent)})`;
        constructor(props){
            super(props);
        }
        render(){
            const {forwardedRef,...rest} = this.props;
            return(
                <div>
                    <h1>这是一个高阶组件</h1>
                    <WrappedComponent ref={forwardedRef}>
                        Ref16
                    </WrappedComponent>
                </div>
            )
        }
    }
    //return LogProps;
    // return React.forwardRef((props,ref)=>{
    //     return <LogProps {...props} forwardedRef={ref} />
    // })
    // return React.forwardRef(
    //     function MyFunction(props,ref){
    //         return <LogProps {...props} forwardedRef={ref} />
    //     }
    // )

    function forwardRef(props,ref){
        return <LogProps {...props} forwardedRef={ref}/>
    }
    const name = WrappedComponent.displayName || WrappedComponent.name;
    forwardRef.displayName = `Ref1516(${name})`;

    return React.forwardRef(forwardRef);
}

// function getDisplayName(WrappedComponent){
//     return WrappedComponent.displayName || WrappedComponent.name || 'Component';
// }

export default Ref1516;
